import time

import requests
url = 'http://huayuxuexiao.com/index.php/api/login/login'
header={
    'Accept-Language': 'zh-CN,zh;q=0.8',
    'User-Agent': 'okhttp-okgo/jeasonlzy',
    'X-Token': '',
    'Content-Type': 'application/x-www-form-urlencoded',
    'Content-Length': '42',
    'Host': 'huayuxuexiao.com',
    'Connection': 'Keep-Alive',
    'Accept-Encoding': 'gzip',

}
data = {
    'uid': '8902',
    'phone': '15236680050',
    'password': '145288',
}

session = requests.session()
html = session.post(url,headers=header,data=data)
print(html.json())

header['X-Token'] = html.json()['data']['token']
# # spid 是课程号 4738 是22课 4739是21  4740 是22课 41 23 、42 24、 43 25   4740是25课



#获取课程
url='http://huayuxuexiao.com/index.php/api/kecheng/kcdetail'
formdata = {
    'uid': '8902',
    'kcid': '108'
}
html = session.post(url, headers=header, data=formdata)
print(html.json())
classList = []
print(html.json()['data']['splist'])
print(len(html.json()['data']['splist']))
for classitem in html.json()['data']['splist']:
    if classitem['jindu'] != '100%':
        print(classitem['id'],classitem['zjname'])
    else:

        # 获取视频时长度
        # time.sleep(1)
        # 刷进度
        print(classitem['id'], classitem['zjname'])
        # 进度提交
        url = 'http://huayuxuexiao.com/index.php/api/Kechengabc/getspjindu_all'

        formdata = {
            'uid': '8902',
            'sparr': '[{"jindu":"100%","spid":"'+str(classitem['id'])+'","times":"","uid":"8902"}]',

        }
        html = session.post(url, headers=header, data=formdata)
        # print(html.text)

        #查看服务器时间
        # print(classitem['id'], classitem['zjname'])
        # # 进度提交
        # url = 'http://huayuxuexiao.com/index.php/api/kecheng/jiyi_get'
        #
        # formdata = {
        #     'uid': '8902',
        #     'sparr': '[{"jindu":"100%","spid":"'+str(classitem['id'])+'","times":"331000","uid":"8902"}]',
        #
        # }
        # html = session.post(url, headers=header, data=formdata)
        # print(classitem['id'],classitem['zjname'],'课程内容',html.text)




